/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : dislpay.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DISPLAY_CTRL_H
#define __DISPLAY_CTRL_H
#include "stdint.h"
#include "stm32f4xx_hal.h"
#include "stdbool.h"

#define MAX_LEN        255
#define MAX_QUEUE_SIZE 10

/* Command definition */
#define CMD_WRITE_REGISTER   0x80
#define CMD_READ_REGISTER    0x81
#define CMD_WRITE_VARIABLE   0x82
#define CMD_READ_VARIABLE    0x83
#define CMD_WRITE_Curve      0x84

/* Read register address definition */
#define VERSION       0x00     /* Terminal version number, BCD code */
#define LEDLM         0x01
#define BZTIME        0x02
#define PICINDEX      0x0003

/* Register data length */
#define DATA_LEN(a)     (a)


#define LENGTH_OFFSET       			 0x02
#define CMD_OFFSET    						 0x03
#define ADDR_OFFSET  						   0x04
#define DATA_OFFSET_OF_REGISTER    0x05
#define DATA_OFFSET    						 0x06
#define Curve_OFFSET    					 0x05

#define BUZZER_REGISTER   				 0x02
#define PAGE_REGISTER   				 	 0x03

#define CHANNEL_0                   0x01
#define CHANNEL_1                   0x02
#define CHANNEL_2                   0x04
#define CHANNEL_3                   0x08
#define CHANNEL_4                   0x10
#define CHANNEL_5                   0x20
#define CHANNEL_6                   0x40
#define CHANNEL_7                   0x80

typedef struct {
	uint8_t rxBuffer[MAX_LEN];
	uint8_t rxBufferIndex;
	uint8_t rxBufferLen;
}RxMessage;

typedef struct 
{
	RxMessage rxMessage;
	bool      isReadingFinishedFlag;
	bool      isReadingTimeoutFlag;
	bool      isInReadingStatus;
	uint8_t   rxTimeoutCnt;
}DisplayReadingHandle;

typedef struct 
{
	RxMessage rxMessageQueue[MAX_QUEUE_SIZE];
	uint8_t   queueHead;
	uint8_t   queueTail;
}DisplayResponseHandle;

typedef struct 
{
	uint8_t rxBufferTemp;
	DisplayReadingHandle   displayReadingHandle;
	DisplayResponseHandle  displayResponseHandle;
}DisplayHandle;

extern HAL_StatusTypeDef Display_Read_Register(uint8_t readAddr, uint8_t* pBuffer, uint8_t numToRead);
extern void Display_Write_Register(uint8_t writeAddr, uint8_t* pData, uint8_t numToWrite);

extern HAL_StatusTypeDef Display_Read_Variable(uint16_t readAddr, uint8_t* pBuffer, uint8_t numToRead);
extern void Display_Write_Variable(uint16_t writeAddr, uint8_t* pData, uint8_t numToWrite);

extern void Display_Write_CurveData(uint8_t channel, uint16_t* pData, uint8_t numToWrite);

void Display_FloatNum(uint16_t channel,float value);
void Display_BzTime(uint8_t Time);
void Display_IntNum(uint16_t channel,int value);
void Skip_to_Page(uint16_t Target_Page);

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/



#ifdef __cplusplus
}
#endif

#endif /* __DISPLAY_CTRL_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
